//
//  Item.m
//  CoreData-Demo
//
//  Created by zhaoguoteng on 2020/4/21.
//  Copyright © 2020 gaven. All rights reserved.
//

#import "Item.h"

@implementation Item

@dynamic title;
@dynamic order;
//@dynamic parent;
//@dynamic children;

+ (instancetype)insertItemWithTitle:(NSString *)title
                             order:(NSInteger)order
                             parent:(Item *)parent
             inManagedObjectContext:(NSManagedObjectContext *)context {
    
//    NSUInteger order = parent.order.integerValue;
    
    NSEntityDescription *entity = [NSEntityDescription entityForName:self.entityName inManagedObjectContext:context];
    
    Item *item = [[Item alloc] initWithEntity:entity
               insertIntoManagedObjectContext:context];

    item.title = title;
//    item.parent = parent;
    item.order = @(order);
    
    return item;
}

+ (NSString *)entityName {
    return @"Item";
}

//- (NSInteger)numberOfChildren {
//    return self.children.count;
//}

@end
